package com.fram.controller.api.android;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseController;
import com.fram.entity.DistributorFarm;
import com.fram.service.api.v1.android.DistributorAndroidService;

@RestController
@RequestMapping("/api/{version}/app/manage/distributor")
public class DistributorAndroidController extends BaseController{

	private static Logger LOG = LoggerFactory.getLogger(DistributorAndroidController.class);
	
	@Autowired
	private DistributorAndroidService distributorAndroidService;
	
	//店铺资料
	@ApiVersion(1.0)
	@RequestMapping("detail")
	private ResponseMsg detail() {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(distributorAndroidService.detail(getDistributorId()));
		} catch (ProException e) {
			LOG.error("-店铺资料详情出错-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--店铺资料详情异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("update")
	private ResponseMsg update(@RequestBody DistributorFarm request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			distributorAndroidService.update(request);
		} catch (ProException e) {
			LOG.error("-店铺资料修改出错-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--店铺资料修改异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
